<?php
/**
* @package Santic
* @author Anor <rpg@santic.pl>
* @license GNU/GPL
* @version 0.1
* @copyright (C) 2006-2008 Santic.pl Powered by Santic Engine based on Vallheru Engine
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

$title = "Podanie o zmianę rangi"; 
require_once("includes/head.php"); if (!$_GET['ajax']) require_once("includes/head_start.php"); 


/**
* Write new message
*/
$danepodania = $db -> Execute("Select * from kandydat where idkandydat=".$player -> id);
if (isset($danepodania -> fields['id']))
{
	require_once('includes/ranks.php');
	$ranga1 = selectrank($danepodania -> fields['rank'], $player -> gender);
	$select = '<option value="'.$danepodania -> fields['rank'].'">'.$ranga1.'</option>';
	$smarty -> assign("Tresc", $danepodania -> fields['text']);
	if ($danepodania -> fields['powod'] == '' || $danepodania -> fields['wysw'] == 'T') $danepodania -> fields['powod'] = 'Oczekuje na rozpatrzenie';
	$smarty -> assign("Stan", '<br><br> Stan podania: '.$danepodania -> fields['powod']);
} else {
	switch ($player -> rank)
	{
	case 'Przybysz':
	$select = '<option value="Member">Mieszkaniec</option>'; break;
	case 'Member':
	$select = '<option value="Przybysz">Przybysz</option><option value="Gwardzista">Gwardzista</option><option value="MG">Mistrz Gry</option><option value="Karczmarka">Karczmarz</option><option value="Skryba">Skryba</option><option value="Prawnik">Prawnik</option>'; break;
	case 'Gwardzista':
	$select = '<option value="Member">Mieszkaniec</option><option value="Kapitan Gwardii">Kapitan Gwardii</option><option value="Przybysz">Przybysz</option>'; break;
	case 'Kapitan Gwardii':
	$select = '<option value="Member">Mieszkaniec</option><option value="Lord">Lord</option><option value="Przybysz">Przybysz</option>'; break;
	default:
	$select = '<option value="Member">Mieszkaniec</option><option value="Przybysz">Przybysz</option>'; break;
	}
	$smarty -> assign("Tresc", '');
}


$smarty -> assign("Select", $select);
$smarty -> assign("Rank", $player -> rank);

if (isset ($_GET['step']) && $_GET['step'] == 'send') 
{
/*	if (empty ($_POST['body'])) 
	{
		error ('Wypełnij wszystko!');
        }
*/
        require_once('includes/bbcode.php');
	if ($_POST['subject'] == 'Member' || $_POST['subject'] == 'Przybysz') $_POST['body'] = '';
        $_POST['body'] = bbcodetohtml($_POST['body']);
        $strBody = $db -> qstr($_POST['body'], get_magic_quotes_gpc());
	$arrRank = array('MG', 'Przybysz', 'Member', 'Staff', 'Sędzia', 'Prawnik', 'Bibliotekarz', 'Rycerz', 'Dama', 'Marszałek Rady', 'Poseł', 'Kanclerz Sądu', 'Królewski Błazen', 'Redaktor', 'Karczmarka','Bohater', 'Prokurator', 'Gwardzista', 'Kapitan Gwardii', 'Skryba', 'Radny');
	if (!in_array($_POST['subject'], $arrRank)) error('Blad!');
        $strSubject = $_POST['subject'];
        if (empty ($strSubject) || empty ($_POST['subject']))
        {
            error ('Wypełnij wszystko!');
        }
        $strDate = $db -> DBDate($newdate);

	if (isset($danepodania -> fields['id']))
	{
		$db -> Execute("UPDATE kandydat SET user='".$player -> user."', text=".$strBody.", date=".$strDate.", rank='".$strSubject."', wysw='T' WHERE idkandydat='".$player -> id."'") or die($db -> ErrorMsg());
	error ('Podanie zaktualizowane!');
	} else {
		$db -> Execute("INSERT INTO kandydat (idkandydat, user, text, date, rank) VALUES('".$player -> id."','".$player -> user."', ".$strBody.", ".$strDate.", '".$strSubject."')") or die($db -> ErrorMsg());
	error ('Podanie wysłane!');
	}

}
if (isset ($_GET['step']) && $_GET['step'] == 'skasuj') 
{
$db -> Execute("DELETE FROM kandydat WHERE idkandydat=".$player -> id);
error ('Podanie skasowane!');
}



if (isset($danepodania -> fields['id']))
{
	$danepodania -> Close();
}

/**
* Initialization of variables
*/
if (!isset($_GET['step']))
{
    $_GET['step'] = '';
}

/**
* Assign variables to template and display page
*/

$smarty -> display ('kandydat.tpl');

if (!$_GET['ajax']) require_once("includes/foot.php"); 
?>
